var createError = require('http-errors')
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var cors = require('cors');
var bodyParser = require('body-parser')

// token登录配置
var expressJWT = require('express-jwt')
var bodyparser = require('body-parser')



// var indexRouter = require('./routes/index');
// var usersRouter = require('./routes/users');

var app = express();

// token登录配置
app.use(bodyparser.json())

app.use(bodyParser.urlencoded({ extended: false }))//解析post请求
app.use(bodyParser.json())//解析json请求


// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(cors());
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/public', express.static(path.join(__dirname, 'public')));

app.use(bodyParser.urlencoded({ extended: false }))//解析post请求
app.use(bodyParser.json())//解析json请求
app.use(express.static(path.join(__dirname, 'upload')));
app.use('/public',express.static(path.join(__dirname, 'public')));
app.use("/upload",express.static(path.join(__dirname,'upload')));

// app.use('/', indexRouter);
// app.use('/users', usersRouter);
app.use('/wmh_index', require('./routes/WMH/index.js'))
app.use('/wmh_user', require('./routes/WMH/users.js'))
app.use('/xxk_index', require('./routes/XXK/index.js'))
app.use('/xxk_user', require('./routes/XXK/users.js'))
app.use('/xxk_ce', require('./routes/XXK/ce.js'))
app.use('/jsb_index', require('./routes/JSB/index.js'))
app.use('/jsb_user', require('./routes/JSB/users.js'))
app.use('/dym_index', require('./routes/DYM/index.js'))
app.use('/dym_user', require('./routes/DYM/users.js'))
app.use('/sxn_index', require('./routes/SXN/index.js'))
app.use('/sxn_user', require('./routes/SXN/users.js'))
app.use('/dqj_index', require('./routes/DQJ/index.js'))
app.use('/dqj_user', require('./routes/DQJ/users.js'))
app.use('/zyw_index', require('./routes/ZYW/index.js'))
app.use('/zyw_user', require('./routes/ZYW/users.js'))
// catch 404 and forward to error handler
app.use(function (req, res, next) {
  next(createError(404));
});

// error handler
app.use(function (err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);
  res.render('error');
});

module.exports = app;
